#include "tcp_client.hpp"

#include "net_common.hpp"

#include <boost/bind.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <string>

using namespace std;

boost::shared_ptr<tcp_client_t> g_tcp_client;

void connection_handler(bool success) {
  if (success) {
    req_t request;
    request.add("---Hello, ").add("server!!!---:").data("data",4);
    g_tcp_client->send(request);
  }
  else {
    cout << "Connection failed" << endl;
  }
}

void disconnected_handler(const std::string &reason) {
  cout << "Disconnected because of: " << reason << endl;
}

void data_handler(const char *buf, size_t size) {
  std::string tmp(buf, size);
  cout << "Message received: " << tmp << endl;
}

int main(int argc, const char ** argv) {

  boost::asio::io_service svc;

  g_tcp_client.reset(new tcp_client_t(svc, boost::asio::ip::address::from_string("127.0.0.1"), tcp_port));

  //g_tcp_client->connected_.connect(connection_handler);
  //g_tcp_client->disconnected_.connect(disconnected_handler);
  //g_tcp_client->on_data_.connect(data_handler);

  g_tcp_client->async_connect();

  svc.run();

  return 0;
}
